//公用样式 
require('../../assets/css/index.less')

require('../../assets/fonts/iconfont.css')
require('../../assets/fonts-wei/iconfont.css')

// 当前页面样式
require('./login.less')

// 引入工具函数
let dom = require('../../utils/dom.js')
//引入axios封装的文件
let https = require('../../utils/https.js');
// 引入本地存储文件
let local = require('../../utils/local.js')

// 当前js
dom.ready(function () {
   //登录功能
   dom.addEvent('#loginBtn', function () {
    console.log(1111);
    //判定账号和密码都有输入
    //1.获取账号和密码
    let userVal = account.value;
    let password = pwd.value;
    //2.判定 
    if (userVal && password) {
        //3.发ajax
        https.post('/api/user/login', {
            account: userVal,
            password
        }, function (res) {
           
            // console.log(res);
            //判定是否登录成功
            if (res.errno == 0) {//成功
       
        
                weui.alert('恭喜你,登陆成功');
                //保存token
                local.set('token', res.data.token)
               
                // 跳转页面----首页
                setInterval(function(){
                    location.href = 'home.html'
                },2000)
              
            } else {//失败
                //给到失败提示
      
                
                weui.alert('您的账号或密码错误！')
            }
        })
    } else {
        weui.alert('请输入账号和密码！')
    }


})


})

